//
//  LogCatNocHelper.m
//  LogCat
//
//  Created by 清风徐来 on 2024/1/5.
//

#import "LogCatNocHelper.h"
#import "LogCat/LogCatManager.h"
#import <UserNotifications/UserNotifications.h>

@interface LogCatNocHelper ()

@end

@implementation LogCatNocHelper

static LogCatNocHelper *_sharedInstance;
+ (instancetype)shared {
    if(_sharedInstance == nil) {
        _sharedInstance = [[LogCatNocHelper alloc] init];
    }
    return _sharedInstance;
}

+(instancetype)allocWithZone:(struct _NSZone *)zone {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedInstance = [super allocWithZone:zone];
    });
    return _sharedInstance;
}

- (id)copyWithZone:(NSZone *)zone {
    return _sharedInstance;
}

- (id)mutableCopyWithZone:(NSZone *)zone {
    return _sharedInstance;
}

/// 检测推送权限是否打开
/// - Parameter completion: 回调
- (void)checkPushNotificationsEnabledWithCompletion:(void (^)(BOOL))completion {
    [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
        BOOL isPushEnabled = (settings.authorizationStatus == UNAuthorizationStatusAuthorized);
        if (completion) {
            completion(isPushEnabled);
        }
    }];
}

/// 打开APP设置
- (void)openAppSettings {
    NSURL *settingsUrl = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if ([[UIApplication sharedApplication] canOpenURL:settingsUrl]) {
        [[UIApplication sharedApplication] openURL:settingsUrl options:@{} completionHandler:nil];
    }
}

@end
